﻿using Autofac;
using Microsoft.AspNetCore.Http;
using SX.Core;
using SX.Core.Auth;
using SX.Core.EventBus.Db;
using SX.ProductService.API.Base;
using SX.ProductService.Repository.Core;
using SX.ProductService.Service.Events;
using SX.ProductService.Service.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace SX.ProductService.API.Autofac
{
    public class AutofacModule:Module
    {
        public AutofacModule()
        {

        }
        /// <summary>
        /// 加载配置数据
        /// </summary>
        /// <param name="builder">容器绑定器</param>
        protected override void Load(ContainerBuilder builder)
        {

            #region 业务
            builder.RegisterType(typeof(SX.ProductService.Service.Implement.Product.ProductService)).As(typeof(IProductService)).InstancePerDependency();
            builder.RegisterType<UserAddIntegrationEventHandler>().InstancePerDependency();

            #endregion

            #region 仓储
            builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>)).InstancePerDependency();
            #endregion
            #region Core
            builder.RegisterType(typeof(PermissionHandler)).As(typeof(IPermissionHandler)).InstancePerDependency();
            builder.RegisterType(typeof(EventLogService)).As(typeof(IEventLogService)).InstancePerDependency();
            builder.RegisterType(typeof(RedisCache)).As(typeof(ICache)).InstancePerLifetimeScope();

            builder.RegisterType<HttpContextAccessor>().As<IHttpContextAccessor>().SingleInstance();

            builder.RegisterType<LoginInfo>().As<ILoginInfo>().SingleInstance();


            #endregion
        }
    }
}
